package pen_exam.p_2024_04_07_smallredbook;

import java.rmi.MarshalledObject;
import java.util.LinkedList;
import java.util.Scanner;

//子序列加和 * 最小值最大
/**
 * goods[]
 * talks[]
 * 选下标 一共k个元素 (子序列) sum（goods[...]) * min(talks[...]) 最大
 * */
public class Code02_BestBook {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] nk = sc.nextLine().split(" ");
        int n = Integer.parseInt(nk[0]);
        int k = Integer.parseInt(nk[1]);
        String[] gos = sc.nextLine().split(" ");
        String[] tas = sc.nextLine().split(" ");
        int[] goods = new int[n];
        int[] talks = new int[n];
        int sum = 0;
        int max = 0;
        for (int i = 0; i < n; i++) {
            goods[i] = Integer.parseInt(gos[i]);
            talks[i] = Integer.parseInt(tas[i]);
            sum +=  goods[i];
            max = Math.max(max,talks[i]);
        }
        int[][] map = new int[n + 1][k + 1];
        if(k <= 0 || k > n){
            System.out.println(0);
        }
        else{
            int res = process(goods, talks,0,0,Integer.MAX_VALUE,k,map);
            System.out.println(res);
        }
    }
    public static int process(int[] goods,int[] talks,int index,int sum,int min,int k,int[][] map){
        if(index == goods.length ){
            int res = k == 0 ? min == Integer.MAX_VALUE ? Integer.MAX_VALUE : sum * min : Integer.MIN_VALUE;
            map[index][k] = res;
            return res;
        }
        if(k == 0){
            map[index][k] = sum * min;
            return sum*min;
        }
        if(map[index][k] != 0){
            return map[index][k];
        }
        int p1 = 0;
        //不要
        p1 = process(goods,talks,index+1,sum,min,k,map);
        int p2 = 0;
        p2 = process(goods,talks,index+1,sum + goods[index],Math.min(min,talks[index]),k - 1,map);
        map[index][k] = Math.max(p1,p2);
        return Math.max(p1,p2);
    }
}
